import { pages } from '@/api/job/deliver'
import { pages as activityPage } from '@/api/activity/activity'

const state = {
  controllerName: 'deliver',
  dataList: {
    activitylist: [],
    listLoading: false,
    list: [], 
    // 投递类型 0：普通投递 1：有活动投递 2：扫过小程序码投递
    deliverTypeList: ['普通投递', '活动投递', '扫小程序码投递'],
    departmentTree: [],
    defaultProps: {
      children: 'departmentList',
      key: 'id',
      label: 'name'
    },
    searchForm: {
      pageSize: 10,
      pageIndex: 1,
      dataCount: 0,
      pageCount: 0
    }
  },
  form: {
    formState: false,
    formDepartmentState: false,
    model: {},
    ResetPwdFormState: false,
    ResetPwdModel: {},
    CategoryOneList: [], // 一级分类
    CategoryTwoList: [], // 二级分类
    CategoryThreeList: [], // 三级分类
    selectedProvince: [], // 选择的省市区
    TextToCode: [], // 选择的省市区
    checkList: [],
    closeState: false,
    closemodel: { type: '0', Reason: '' }

  }
}
const mutations = {
  pageSizeChange(state, par) {
    state.dataList.searchForm.pageSize = par
    this.dispatch(`job/${state.controllerName}/findList`)
  },
  currentPageChange(state, par) {
    state.dataList.searchForm.pageIndex = par
    this.dispatch(`job/${state.controllerName}/findList`)
  }
}

const actions = {
  getactivitylist(context, par) {
    var _state = context.state
    activityPage({
      pageSize: 1000,
      pageIndex: 1
    })
      .then(res => {
        const { Data } = res
        _state.dataList.activitylist = Data.List
      })
      .catch(e => {
        console.log(e)
      })
  },
  findList(context, par) {
    var _state = context.state
    _state.dataList.listLoading = true
    pages(_state.dataList.searchForm)
      .then(res => {
        const { Data } = res
        console.log(Data)
        _state.dataList.list = Data.List
        _state.dataList.searchForm.pageIndex = Data.PageIndex
        _state.dataList.searchForm.pageSize = Data.PageSize
        _state.dataList.searchForm.dataCount = Data.Count
        _state.dataList.searchForm.pageCount = Data.Pages
        _state.dataList.listLoading = false
        context.dispatch('getactivitylist')
      })
      .catch(error => {
        console.log(error)
      })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
